package com.shakev.coupon.data.mysql.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shakev.coupon.business.model.AppVersionDto;
import com.shakev.coupon.business.util.rest.RestResponse;
import com.shakev.coupon.data.mysql.entity.AppVersion;
import com.shakev.coupon.data.mysql.service.IAppVersionService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lws
 * @since 2019-06-13
 */
@RestController

public class AppVersionController {

    @Resource
    IAppVersionService appVersionService;

    @RequestMapping("/app/version")
    public RestResponse getVersion(){
        QueryWrapper<AppVersion> query = new QueryWrapper<>();
        query.eq(true,"is_enable",1);
        AppVersion res = appVersionService.getOne(query);
        if(res!=null){
            AppVersionDto dto = new AppVersionDto();
            BeanUtils.copyProperties(res,dto);
            if(res.getGmtCreate()!=null){
                dto.setCreateTime(res.getGmtCreate().getTime());
            }
            return RestResponse.success(dto);
        }
        return RestResponse.success();
    }

}
